import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import '../../../../res/colors.dart';
import '../../../../res/style.dart';
import '../../../../widget/ripple_widget.dart';

class SelectCommonTool extends StatefulWidget {
  String title;
  RxString selectTitle;
  String placeholder;
  GestureTapCallback? onTap;
  GestureTapCallback? clearTap;

  SelectCommonTool(
      {Key? key,
      required this.title,
      required this.selectTitle,
      this.onTap,
      this.placeholder = '',
      this.clearTap})
      : super(key: key);

  @override
  State<SelectCommonTool> createState() => _SelectCommonToolState();
}

class _SelectCommonToolState extends State<SelectCommonTool> {
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: double.infinity,
      child: GestureDetector(
        onTap: widget.onTap,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            SizedBox(
              width: 90.w,
              child: Text(
                widget.title,
                style: Styles.style_9F9EA6_16,
              ),
            ),
            Expanded(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Obx(() {
                    return SizedBox(
                      width: double.infinity,
                      child: Text(
                        widget.selectTitle.value,
                        style: Styles.style_red_16,
                        textAlign: TextAlign.start,
                        // overflow: TextOverflow.ellipsis,
                      ),
                    );
                  }),
                ],
              ),
            ),
            widget.placeholder.isEmpty ||
                    widget.placeholder == widget.selectTitle.value
                ? const Icon(
                    Icons.chevron_right,
                    color: ColorStyle.color_home,
                  )
                : Ripple(
                    onTap: widget.clearTap,
                    child: const Padding(
                      padding: EdgeInsets.all(5),
                      child: Icon(
                        Icons.cancel_rounded,
                        color: ColorStyle.color_home,
                        size: 18,
                      ),
                    )),
          ],
        ),
      ),
    );
  }
}
